﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _97基本数据类型的转换
{
    internal class Program
    {
        //隐式转换 低范围到高范围
        private static void Main1(string[] args)
        {
            int a = 1234567891;
            float f = a;

            int a1 = 123;
            double d1 = a1;

            int a2 = 123;
            long l1 = a2;
        }

        //强制转换 高范围到低范围    失败会得到没有意义的数字
        private static void Main2(string[] args)
        {
            int i = 255;
            short b = (short)i;
            Console.WriteLine(b);

            uint a2 = 123;
            int a1 = (int)a2;

            long l1 = 123;
            short s1 = (short)l1;

            ulong u1 = 123;
            short s2 = (short)u1;
        }

        //Convert转换      转换失败会抛出异常
        private static void Main3(string[] args)
        {
            int a = 256;
            //byte b =(byte) a;
            byte b = Convert.ToByte(a);
            Console.WriteLine(b);
        }
        //使用Convert把数字转换成01字符粗
        private static void Main4(string[] args)
        {
            int i = 15;
            string s = Convert.ToString(i, 2);
            Console.WriteLine(s);
        }

        //parse转换
        private static void Main5(string[] args)
        {
            // Console.WriteLine("请输入第一个数字:");
            // int n1 = int.Parse(Console.ReadLine());
            // Console.WriteLine("请输入第二个数:");
            // int n2 = int.Parse(Console.ReadLine());
            // Console.WriteLine(n1 + n2);

            string s1 = "1.23";
            float f1 = float.Parse(s1);
        }
        //任意类型转字符串   变量名.ToString();
        private static void Main(string[] args)
        {
            int i = 123;
            string s = i.ToString();
        }
    }
}